﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Xrm.Solutions.FrameworkSample.Common
{
    public class CreditLimitServiceHD : ICreditLimitService
    {
        private IIdentityCheckService Service { get; set; }

        public CreditLimitServiceHD()
        {
            Service = new IdentityCheckService();
        }

        public int IncreaseLimit(string firstname,
                                string lastname,
                                DateTime dob,
                                string address,
                                int currentLimit,
                                int requestedLimit)
        {
            int score = Service.RunCheck(firstname,
                                            lastname,
                                            dob,
                                            address);

            if (score > 90)
            {
                if (requestedLimit < (int)(currentLimit * 1.5))
                {
                    return requestedLimit;
                }
                else
                {
                    return (int)(requestedLimit * 1.5);
                }
            }
            else
            {
                return currentLimit;
            }
        }
    }
}
